//
//  SEGServiceHotlineCell.m
//  Commom
//
//  Created by 乔杨 on 2019/5/6.
//

#import "SEGServiceHotlineCell.h"


@interface SEGServiceHotlineCell()

/** 背景图 */
@property (nonatomic, strong) UIImageView *bgImageView;
/** 头像 */
@property (nonatomic, strong) UIImageView *iconImageView;
/** 名字 */
@property (nonatomic, strong) UILabel *nameLab;

@end

@implementation SEGServiceHotlineCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createUI];
    }
    return self;
}

- (void)createUI {
    [self.contentView addSubview:self.bgImageView];
    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.left.right.equalTo(self.contentView);
        make.height.width.equalTo(self.contentView);
    }];
    [self.contentView addSubview:self.iconImageView];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(9.5*kScaleWidth);
        make.width.mas_equalTo(282.5*kScaleWidth);
        make.height.mas_equalTo(211*kScaleWidth);
    }];
    [self.contentView layoutIfNeeded];
    UIBezierPath *bezierPath = [UIBezierPath bezierPathWithRoundedRect:self.iconImageView.bounds byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight cornerRadii:CGSizeMake(10, 10)];
    CAShapeLayer *layer = [CAShapeLayer layer];
    layer.path = bezierPath.CGPath;
    self.iconImageView.layer.mask = layer;
    
    [self.contentView addSubview:self.nameLab];
    [self.nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.contentView.mas_centerX);
        make.top.equalTo(self.iconImageView.mas_bottom).offset(50*kScaleWidth);
        make.width.mas_equalTo(self.iconImageView.width-10);
    }];
}

- (void)refreshCellWithModel:(SEGServiceHotlineModel *)model {
    self.nameLab.text = model.userName;
    NSURL *iconUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kClientImageRootURL, model.icoPath]];
    [self.iconImageView setImageWithURL:iconUrl
                       placeholderImage:[UIImage imageNamed:SEGPicName(@"pic_guanjia_head")]];
}

#pragma mark - Getter
- (UIImageView *)bgImageView {
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc] init];
        _bgImageView.image = [UIImage imageNamed:SEGPicName(@"pic_fwrx_card_bg")];
    }
    return _bgImageView;
}
- (UIImageView *)iconImageView {
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        _iconImageView.layer.cornerRadius = 5.f;
        _iconImageView.layer.masksToBounds = YES;
    }
    return _iconImageView;
}
- (UILabel *)nameLab {
    if (!_nameLab) {
        _nameLab = [[UILabel alloc] init];
        _nameLab.textAlignment = NSTextAlignmentCenter;
        _nameLab.font = [UIFont boldSystemFontOfSize:25];
        _nameLab.textColor = kColor_1;
    }
    return _nameLab;
}

@end
